/**
  ******************************************************************************
  * @file    RTC.h
  * @author  Qilong Huang
  * @version V0.0.1
  * @date    04-03-2020 
  * @brief   This file contains headers for RTC function
  *				 
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */

#ifndef __RTC_H_
#define __RTC_H_

#include "stm32f10x.h"
#include "global.h"
#include "stm32f10x_rcc.h"
#include "Menu.h"

#define RTC_CLOCK_SOURCE_LSE
#define USING_ONCHIP_RTC

#define UNIX_TIME_YEAR	1970
#define UNIX_TIME_MONTH	1
#define UNIX_TIME_DATE	1
#define UNIX_TIME_HOUR	0
#define UNIX_TIME_MINIUTE	0
#define UNIX_TIME_SECOND	0
#define LEAP_YEAR			1
#define FLAT_YEAR			0

typedef struct
{
    U16 t_year;
    U8 t_mounth;
    U8 t_date;
    U8 t_hour;
    U8 t_min;
    U8 t_sec;
    U8 t_date_am;
} t_tm;

typedef enum
{
	GTM_W12 = -12,
	GTM_W11 = -11,
	GTM_W10 = -10,
	GTM_W9	= -9,
	GTM_W8  = -8,
	GTM_W7  = -7,
	GTM_W6  = -6,
	GTM_W5  = -5,
	GTM_W4  = -4,
	GTM_W3  = -3,
	GTM_W2	= -2,
	GTM_W1  = -1,
	GTM_0	= 0,				//Zero square
	GTM_E1	= 1,
	GTM_E2  = 2,
	GTM_E3  = 3,
	GTM_E4  = 4,
	GTM_E5  = 5,
	GTM_E6  = 6,
	GTM_E7  = 7,
	GTM_E8  = 8,
	GTM_E9  = 9,
	GTM_E10 = 10,
	GTM_E11 = 11,
	GTM_E12 = 12,
}t_gtm;

extern u32 cnt_temp;
extern t_tm sys_time;
extern t_tm set_time;
extern void RTC_Configuration(void);
extern void RTC_Initial(void);
extern void cnt_to_time(U32 input_time_cnt, t_tm *output_time);
extern U32 time_to_second(t_tm *input_time);
extern U32 gtm_time_trans_areas_cnt(t_gtm time_square, t_tm *input_time);
extern U32 local_time_trans_gtm_cnt(t_gtm time_square, t_tm *input_time);
extern void gtm_time_to_trans_areas(t_gtm time_square, t_tm *input_time, t_tm *output_time);
extern void get_current_time(void);
extern void local_time_to_gtm(t_gtm time_square, t_tm *input_time, t_tm *output_time);
extern void set_gtm_rtc_counter(U32 rtc_counter);
extern u32 GetSystemTime(void);

#endif

